package com.itheima.web.listener;

import com.itheima.autoconfig.huawei.HuaWeiUGCTemplate;
import com.itheima.domain.db.Log;
import com.itheima.domain.mongo.Movement;
import com.itheima.service.db.LogService;
import com.itheima.service.mongo.MovementService;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(topic = "tanhua-huawei", consumerGroup = "huawei")
public class HuaweiMQListener implements RocketMQListener<String> {

    @Reference
    private MovementService movementService;

    /**
     * 后台理论上还有 循环已经修改的动态进行审核
     */
    @Autowired
    private HuaWeiUGCTemplate huaWeiUGCTemplate;
    @Override
    public void onMessage(String movementId) {
        //1.查询到需要审核的动态
        Movement movement = movementService.findMovementById(movementId);
        //2.审核图片
        boolean flag1 = huaWeiUGCTemplate.imageContentCheck(movement.getMedias().toArray(new String[]{}));
        //3.审核文字
        boolean flag2 = huaWeiUGCTemplate.textContentCheck(movement.getTextContent());
        if(flag1 && flag2){
            //4.如果都通过的前提下 修改状态 为1
            movement.setState(1);
            movementService.updateMovement(movement);
        }else{
            //4.如果有一个不通过修改状态为0
            movement.setState(0);
            movementService.updateMovement(movement);
        }


    }
}
